/**
 * 
 * VIEW of resizable pane...
 * 
 * @Ning
 * 
 * 2010-4-7
 * 
 * 
 * 
 * */
package com.components.pane.resizable
{
	import core.section.Controller;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import mx.core.Container;
	import mx.core.UIComponent;
	
	public class ResizablePaneView extends Controller
	{
		//START...
		
		
		//PROPERTY...
		
		private var weight:Number;
		
		internal var consolContainer:Sprite;
		
		internal var consolUIs:Array;
				
		internal static const CONSOLS:Array = ["tl","t","tr","l","r","bl","b","br"];
		
		
		//CONSTRUCTOR...
		public function ResizablePaneView(target:DisplayObject,weight:Number)
		{
			super(target);
			
			this.weight = weight;
			
			init();
			
		}
		
		//METHODS...
		
		// initializing...
		private function init():void
		{
			
			if(target is UIComponent)
			{
				
				consolContainer = new UIComponent;
				
				
			}else{
				
				consolContainer = new Sprite;
				
			}	
			
			
			(target as Sprite).addChild(consolContainer);
			
			consolUIs = new Array;
			
			for(var i:int = 0;i < CONSOLS.length;i++)
			{
				
				var console:DisplayObject = createConsolUI(CONSOLS[i]);
				
				consolContainer.addChild(console);
				
				consolUIs.push(console);
				
			}	
			
		}	
		
		// crate consol ui...
		private function createConsolUI(type:String,consol:MovieClip = null):DisplayObject
		{
			
			consol = consol ? consol : new MovieClip;
			
			consol.graphics.clear();
			
			consol.graphics.beginFill(0x99FF00,0);
			
			switch(type)
			{	
				
				case "tl":
				
				consol.graphics.drawRect(0,0,weight,weight);
					
				break;
				
				case "t":
					
				consol.x = weight;	
				
				consol.graphics.drawRect(0,0,target.width - weight * 2,weight);	
					
				break;
				
				case "tr":
				
				consol.x = target.width;	
					
				consol.graphics.drawRect(0 - weight,0,weight,weight);	
					
				break;
				
				case "l":
					
				consol.y = weight;
					
				consol.graphics.drawRect(0,0,weight,target.height - weight * 2);	
					
				break;
				
				case "r":
					
				consol.x = target.width - weight;
				
				consol.y = weight;
				
				consol.graphics.drawRect(0,0,weight,target.height - weight * 2);	
					
				break;
				
				case "bl":
					
				consol.y = target.height - weight;	
				
				consol.graphics.drawRect(0,0,weight,weight);	
					
				break;
				
				case "b":
				
				consol.x = weight;
				
				consol.y = target.height - weight;
					
				consol.graphics.drawRect(0,0,target.width - weight * 2,weight);	
					
				break;
				
				case "br":
				
				consol.x = 	target.width - weight;
				
				consol.y = target.height - weight;
					
				consol.graphics.drawRect(0,0,weight,weight);	
					
				break;
				
			}
			
			consol.graphics.endFill();
			
			return consol;
			
		}	
		
		//drag view...
		internal function dragingView():void
		{
			
			(target as Sprite).mouseEnabled = false;
			
			(target as Sprite).mouseChildren = false;
			
		}	
		
		// fit size to target...
		internal function fitSizeToTarget():void
		{
			
			consolContainer.x = 0;
			
			consolContainer.y = 0;
			
			for(var i:int = 0;i < consolUIs.length;i++)
			{
				
				createConsolUI(CONSOLS[i],consolUIs[i])
				
			}	
			
		}	
		
		//END...
	}
}